package cn.tedu.blog.server.controller.system;

import cn.tedu.blog.server.pojo.dto.BannerAddDTO;
import cn.tedu.blog.server.pojo.dto.BannerEditDTO;
import cn.tedu.blog.server.pojo.vo.BannerListVO;
import cn.tedu.blog.server.service.IBannerService;
import cn.tedu.blog.server.utils.JsonPage;
import cn.tedu.blog.server.utils.JsonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private IBannerService bannerService;
    
    @PostMapping("/insert")
    @ApiOperation("添加轮播图")
    public JsonResult insertBanner(BannerAddDTO bannerAddDTO) {
        bannerService.insertBanner(bannerAddDTO);
        return JsonResult.ok();
    }
    
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据id删除轮播图")
    public JsonResult deleteBannerById(@PathVariable Long id) {
        bannerService.deleteBanner(id);
        return JsonResult.ok();
    }
    
    @PostMapping("/deletes")
    @ApiOperation("批量删除轮播图")
    public JsonResult deleteBannerByIds(Long... ids) {
        bannerService.deleteBannerByIds(ids);
        return JsonResult.ok();
    }
    
    @PostMapping("/update")
    @ApiOperation("修改轮播图")
    public JsonResult updateBanner(BannerEditDTO bannerEditDTO) {
        bannerService.updateBanner(bannerEditDTO);
        return JsonResult.ok();
    }
    
    @GetMapping("/list")
    @ApiOperation("分页查询轮播图")
    public JsonResult listBanner(Integer page, Integer pageSize) {
        JsonPage<BannerListVO> jsonPage = bannerService.listBanner(page, pageSize);
        return JsonResult.ok(jsonPage);
    }
    
    @GetMapping("/list/status1")
    @ApiOperation("分页查询status=1的轮播图")
    public JsonResult listBannerByStatus1(Integer page, Integer pageSize) {
        JsonPage<BannerListVO> jsonPage = bannerService.listBannerByStatus1(page, pageSize);
        return JsonResult.ok(jsonPage);
    }

    @GetMapping("/list/status0")
    @ApiOperation("分页查询status=0的轮播图")
    public JsonResult listBannerByStatus0(Integer page, Integer pageSize) {
        JsonPage<BannerListVO> jsonPage = bannerService.listBannerByStatus0(page, pageSize);
        return JsonResult.ok(jsonPage);
    }
    
}
